<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="com.java.service.*,java.util.*,com.java.model.UserSession,com.java.util.*"%>
<%@ taglib uri="/WEB-INF/commontags.tld" prefix="common" %><%--페이징처리tag--%>
<jsp:include page="common/header.jsp"></jsp:include>
<%
	UserSession usersession = (UserSession)session.getAttribute("user");
	String ent_id 			= (String)session.getAttribute("ent_id");
	
	String connGroup 	= "";
	String user_id 		= "";
	if(usersession!=null){
		connGroup 	= CmmUtil.nvl(usersession.getConnGroup(),"0");
		user_id 	= CmmUtil.nvl(usersession.getUser_id(),"");
	}
	String keyword_gb 	= CmmUtil.nvl(request.getParameter("search_gb"),"");
	String keyword 		= CmmUtil.nvl(request.getParameter("search_word"),"");
	String keyword2 	= CmmUtil.nvl(request.getParameter("search_word"),"");
	String line_number	= CmmUtil.nvl(request.getParameter("line_number"),"10");
	
	System.out.println("keyword  " + keyword);

	//페이징 처리 Start
 	//페이지 표시정보 받기 혹은 검색입력창
 	String curr_page = request.getParameter("curr_page");
 	if (curr_page == null || curr_page.equals(""))
 		curr_page = "1";
 	String one_page = request.getParameter("one_page");
 	if (one_page == null || one_page.equals(""))
 		one_page = "10";
 	String one_group = request.getParameter("one_group");
 	if (one_group == null || one_group.equals(""))
 		one_group = "10";
 	
 	String total_count = CmmUtil.nvl(request.getParameter("total_count"),"0");
 	
 	//페이징 처리 End

 	
	HashMap map = new HashMap();
	HashMap map1 = null;
	ArrayList list = new ArrayList();
	CommonDaoService commonservice = new CommonDaoService("Com0401lp01Dao");

	map.put("search_combo",keyword_gb);
	map.put("keyword",keyword);
	map.put("ent_id",ent_id);
	map.put("page_row",line_number);
	map.put("total_row",total_count);
	map.put("page_no",curr_page);
	
	list = (ArrayList)commonservice.commonDaoMethod(map);
	

	if(list != null){
		if(list.size() > 0){
			total_count = (String)((HashMap)list.get(0)).get("total_row");
			System.out.println("total_count " + total_count);
		}
	}
	
	if(list.size() == 0){
		total_count = "0";
	}
	
	//리스트에 뿌릴 사용자 정보
	String id 			="";
	String title 		="";
	String write_name 	="";
	String write_dt		="";
	String read_cnt 	="";
	String rownum		="";
	String r_num		="";
	String blt_cont_no	="";
	
%>
<script>
function search(){
	var frm = document.mainfrm;
	frm.action = "?";
	frm.target="_self";
	frm.curr_page.value ="1";
	frm.total_count.value=0;
	frm.submit();
}

// 페이지 번호를 눌렸을때.
function go_page(page){
	var frm = document.mainfrm;
	frm.curr_page.value = page ;			
	frm.total_count.value = "<%=total_count%>";
	frm.search_word.value = "<%=keyword%>";
	frm.action = "?";
	frm.target="_self";
	frm.submit();
}
function go_detail(blt_cont_no){
	var frm = document.mainfrm;
	frm.blt_cont_no.value = r_num;
	frm.action = "/jsp/com0401l_p02.jsp";	
	frm.method = "post";
	frm.submit();	
}
function checkkeycode(event){
	if ( event.keyCode == 13 ) {
		search();
	} 
}
</script>
<body>
<form name="mainfrm" method="post">
<input type="hidden" name="curr_page" value="<%=curr_page%>">
<input type="hidden" name="total_count" value="<%=total_count%>">
<input type="hidden" name="blt_cont_no" value="">
<input type="hidden" name="ent_id" value="<%=ent_id %>">
<table width="992" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td><!--top -->
    <jsp:include page="common/top_menu.jsp"></jsp:include> 
    <!-- //top -->
    <!-- contents area -->
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="180" valign="top">
    	<jsp:include page="left/com0401l_left.jsp"></jsp:include> 
    </td>
    <td width="21" valign="top">&nbsp;</td>
    <td valign="top">
    	 <table width="790px"  border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td style="font-size:14px; color:#3b70a2; font-weight:bold; border-bottom:2px solid #c8c8c8; padding:0 0 5px 0;" align="left"><img src="/images/sub_icon1.jpg"  alt="" border="0">&nbsp;공지사항</td>
             </tr>
        </table>
         <table width="790px" border="0" cellpadding="0" cellspacing="0" style="margin:20px 0 0 0">
           <tr>
             <td align="left">
             	<jsp:include page="common/selectbox_list.jsp"></jsp:include> 
             </td>
             <td align="right">
             	<select name="search_gb">
                 <option value="1" <%if(keyword_gb.equals("1")){%>selected<%}%>>제목</option>
                 <option value="2" <%if(keyword_gb.equals("2")){%>selected<%}%>>작성자</option>
               </select>
           		<input type="text" name="search_word" value="<%=keyword2 %>" class="textbox" onKeypress="checkkeycode(event);" required="required" hname="검색어" />
                <input type="image" src="/images/bt_search2.gif" align=absmiddle />
             </td>
           </tr>
         </table>
         <table width="790px" border="0" cellspacing="0" class="bbs_property" summary="" style="font-size:11px; margin:13px 0 20px 0;">
            <caption></caption>
            <thead>
             <tr>
              <th>No</th>
              <th>제목</th>
              <th>등록일</th>
              <th>작성자</th>
			  <th>조회수</th>
              <th>선택</th>
             </tr>
            </thead>
            <tbody>
<%		if(list != null && list.size() > 0){
            for(int i=0; i<list.size(); i++){
            	map1 			= (HashMap)list.get(i);
            	r_num 			= CmmUtil.nvl((String)map1.get("r_num"),"");
            	blt_cont_no 	= CmmUtil.nvl((String)map1.get("blt_cont_no"),"");
            	write_name 		= CmmUtil.nvl((String)map1.get("blt_nm"),"");
            	title 			= CmmUtil.nvl((String)map1.get("title"),"제목 없음");
            	write_dt		= CmmUtil.nvl((String)map1.get("reg_dt") ,"--");
            	read_cnt		= CmmUtil.nvl((String)map1.get("read_cnt") ,"0");
            	rownum			= CmmUtil.nvl((String)map1.get("rownum") ,"");
%>
             <tr>
              <td scope="row" class="ranking"><%=r_num%></td>
              <td style="background:#ebf7d4; text-align;left" align="left">&nbsp;<a href="javascript:go_detail('<%=r_num%>')"><%=title%></a></td>
              <td><%=write_dt%></td>
			  <td><%=write_name%></td>
              <td><%=read_cnt%></td>
              <td><input type="checkbox" onclick=""></td>
             </tr>
				<%}
            }else{ %>
             <tr>
             	<td colspan="9">데이터가 없습니다</td>
             </tr>
            <%} %>
 
            </tbody>
            </table>
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
             <tr>
  
                <td align="right">
                	<table width="100%" border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <td width="170px" style="padding:0 0 8px 0; font-weight:bold; color:#FF6600;" align="left">총 : <%=total_count %> 건</td>
                        <!-- 페이징 -->
                       <common:pagelistnew currPage="<%=curr_page%>" total="<%=total_count%>" onePage="<%=one_page%>" oneGroup="<%=one_group%>"/>
                        <!-- //페이징 -->
                      </tr>
                    </table>
           	  		<table width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                        <td align="right">
                        <input name="button2" type="button" class="btn_orange_b_w47" value="등록" onClick="window.location='/jsp/com0401l_p02.jsp'"/><input name="button3" type="button" class="btn_gray_blue2"  value="삭제" onclick="window.location='http://www.naver.com'"/>
                        </td>
                        </tr>
                    </table> 
               </td>
             </tr>
           </table>
    </td>
    </tr>
	</table>
   
    <jsp:include page="common/footer.jsp"></jsp:include>
        </tr>
    </table>
	</td>
  </tr>
</table>
</form>
</body>
</html>
